<?php

namespace app\admin\model;

use app\common\model\Base;

class UserNotice extends Base {
  protected $name = 'user_notice';
  protected $updateTime = FALSE;


  public function initialize() {
    parent::initialize();
  }


  public function unReadIds($uid = NULL) {
    $model = new Notice();
    $uid = $uid ? $uid : session('user_id');
    $map = ['uid' => $uid];
    $readIds = self::where($map)->column('nid');
    $map = [
      'id' => ['not in',
               $readIds],
    ];

    return $model->where($map)->column('id');
  }

  public function unRead($uid=null) {
    $model = new Notice();
    $uid = $uid ? $uid : session('user_id');

    $map = ['uid' => $uid];
    $readIds = self::where($map)->column('nid');
    $map = [
      'id' => ['not in',
               $readIds],
    ];

    return $model->where($map)->select();
  }
}